<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    表单添加多组规则 |  Shimmer
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/myBlog/images/ayer.svg" />
  
  
<link rel="stylesheet" href="/myBlog/dist/main.css">

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">
  
<link rel="stylesheet" href="/myBlog/css/custom.css">

  
  <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
  
  

  

<link rel="alternate" href="/myBlog/atom.xml" title="Shimmer" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    
      
      <canvas width="1777" height="841"
        style="position: fixed; left: 0px; top: 0px; z-index: 99999; pointer-events: none;"></canvas>
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-2021-07-30-表单添加多组规则"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  表单添加多组规则
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/myBlog/2021/07/30/2021-07-30-%E8%A1%A8%E5%8D%95%E6%B7%BB%E5%8A%A0%E5%A4%9A%E7%BB%84%E8%A7%84%E5%88%99/" class="article-date">
  <time datetime="2021-07-29T16:00:00.000Z" itemprop="datePublished">2021-07-30</time>
</a>   
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">2.3k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">12 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      



  
    <div class="article-entry" itemprop="articleBody">
       
  <p><strong>起因</strong></p>
<p>框架 react+ant3（老项目重构很难）</p>
<p>新版本一个需求原型如下：[<img src="https://z3.ax1x.com/2021/07/30/WX1q58.png" alt="WX1q58.png"></p>
<p>可以有多个规则，且规则之间时间需要连续。上一个结束时间的第二天要是下一个规则的开始时间。</p>
<p>如果第一个结束时间是 7 月 30 号,下个月的开始时间要是 7.31 号。依次类推。</p>
<p>还要可以批量设置。就是一次性设置多个。</p>
<p>首先肯定想到的是用数组 map,用的 form 表单。就新建一个数组<code>arr=[0]</code>,点击添加按钮的时候就再<code>push</code>一个 0，删除按钮就<code>arr.splice(index,1)</code>,index 是当前元素下标。但是<code>form.item</code>的依赖字段会重复。</p>
<p>然后只能自己用<code>datePicker、Input</code>还有框架封装好的获取企业 Id 的模糊查询的组件。</p>
<p>且有规则后再修改可以回显数据。</p>
<p>如下：</p>
<p>这是外层的 Modal:</p>
<p>因为批量多个参数逗号分隔。</p>
<p>初始化<code>indexOf</code>判断有没有逗号，是单个还是批量，单个的话就获取数据，且把获取到的数据通过 props 传到子组件当中。因为 render 是先 render。所以这里用个 flag。保证获取到的数据可以传到子组件。</p>
<p>再把需要的一些方法传到子组件当中。</p>
<p>子组件中，通过<code>onChange</code>获取到值放到一个对象中添加到数组里。</p>
<p>添加的时候获取到当前的结束时间。通过<code>moment().add(1,&#39;day&#39;)</code>当然这里要判断是不是数组中的第一个</p>
<p>还有就是对时间的判断。</p>
<p>因为时间的连续的删除只能删除最后一个。</p>
<p>基本完成了功能，但是感觉很冗余，还要修改，一些细节还要完善。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br></pre></td><td class="code"><pre><span class="line">import React,&#123;Component&#125; from &#39;react&#39;</span><br><span class="line">import &#123;  Form, Button, Input, message &#125; from &quot;antd&quot;</span><br><span class="line">import fetchHandler from &#39;@&#x2F;fetch&#x2F;fetchHandler&#39;</span><br><span class="line">import TrusteeshipForm from &#39;.&#x2F;TrusteeshipForm&#39;;</span><br><span class="line">import moment from &#39;moment&#39;;</span><br><span class="line">import &#123;settlementSetting,getSettlementSetting&#125; from &#39;@&#x2F;fetch&#x2F;fetchApi&#39;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">class Trusteeship extends Component &#123;</span><br><span class="line">  constructor(props) &#123;</span><br><span class="line">      super(props)</span><br><span class="line">      this.props &#x3D; props</span><br><span class="line">      this.state &#x3D; &#123;</span><br><span class="line">          domArr : [],</span><br><span class="line">          stubId:this.props.stubId,</span><br><span class="line">          info:[],</span><br><span class="line">          flag:true</span><br><span class="line">      &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">  componentWillMount() &#123;</span><br><span class="line">      this.getInfo()</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line"> async getInfo () &#123;</span><br><span class="line">    if(this.props.stubId.indexOf(&#39;,&#39;)&gt;0) &#123;</span><br><span class="line">        return</span><br><span class="line">    &#125;</span><br><span class="line">    this.setState(&#123;</span><br><span class="line">        flag:false</span><br><span class="line">    &#125;)</span><br><span class="line">    await fetchHandler(getSettlementSetting,&#123;</span><br><span class="line">        stubId:this.props.stubId</span><br><span class="line">    &#125;).then( (res)&#x3D;&gt;&#123;</span><br><span class="line">        if(res&amp;&amp;res.code&#x3D;&#x3D;&#x3D;&#39;success&#39;) &#123;</span><br><span class="line">           const domArr &#x3D; []</span><br><span class="line">            res.data.map((item,index)&#x3D;&gt;&#123;</span><br><span class="line">                     let obj &#x3D; &#123;&#125;</span><br><span class="line">                     obj.unitPrice &#x3D; item.unitPrice</span><br><span class="line">                     obj.paymentCompanyId&#x3D;item.paymentCompanyId</span><br><span class="line">                     obj.startDate &#x3D; moment(item.startDate).format(&quot;YYYY-MM-DD&quot;)</span><br><span class="line">                     obj.endDate &#x3D; moment(item.endDate).format(&quot;YYYY-MM-DD&quot;)</span><br><span class="line">                     obj.companyName &#x3D; item.companyName</span><br><span class="line">                     domArr.push(obj)</span><br><span class="line">           &#125;)</span><br><span class="line">             this.setState(&#123;</span><br><span class="line">                 domArr,</span><br><span class="line">                 info:res.data,</span><br><span class="line">                 flag:true</span><br><span class="line">             &#125;)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  onAdd &#x3D; (newArr)&#x3D;&gt;&#123;</span><br><span class="line">        this.setState(&#123;</span><br><span class="line">            domArr:newArr</span><br><span class="line">        &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">  onDel &#x3D; ()&#x3D;&gt;&#123;</span><br><span class="line">    const domArr &#x3D; this.state.domArr</span><br><span class="line">    domArr.splice(domArr.length-1,1)</span><br><span class="line">    this.setState(&#123;</span><br><span class="line">        domArr</span><br><span class="line">    &#125;)</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;    判断对象是否存在空值</span><br><span class="line">   getDetaios(arr) &#123;</span><br><span class="line">    for (var i in arr) &#123;</span><br><span class="line">      if (arr[i] &#x3D;&#x3D; null) &#123;</span><br><span class="line">        return true</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    return false</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">   onChange &#x3D; (obj)&#x3D;&gt;&#123;</span><br><span class="line">    this.props.form.setFieldsValue(&#123;</span><br><span class="line">        stubPeriodSetting: obj</span><br><span class="line">    &#125;)</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">onFinish &#x3D; (e) &#x3D;&gt; &#123;</span><br><span class="line">    const domArr &#x3D; this.state.domArr</span><br><span class="line">    const isNull &#x3D; this.getDetaios(domArr[domArr.length-1])</span><br><span class="line">    console.log(domArr);</span><br><span class="line">    if(isNull) &#123;</span><br><span class="line">        message.warning(&quot;存在未填项或开始时间在结束时间之前，请检查&quot;)</span><br><span class="line">        return</span><br><span class="line">    &#125;</span><br><span class="line">    e.preventDefault();</span><br><span class="line">    this.props.form.validateFields((err, values) &#x3D;&gt; &#123;</span><br><span class="line">        if (!err) &#123;</span><br><span class="line">            values.stubIds &#x3D; this.state.stubId</span><br><span class="line">            fetchHandler(settlementSetting,values ).then((res) &#x3D;&gt; &#123;</span><br><span class="line">                console.log(res);</span><br><span class="line">                if (res.code &#x3D;&#x3D;&#x3D; &quot;success&quot;) &#123;</span><br><span class="line">                    message.success(&quot;保存成功！&quot;)</span><br><span class="line">                    this.props.fresh()</span><br><span class="line">                    this.props.onCancel()</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;)</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">&#125;;</span><br><span class="line">setFlag  () &#123;</span><br><span class="line">    this.setState(&#123;</span><br><span class="line">        flag:true</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">render () &#123;</span><br><span class="line">    const &#123;getFieldDecorator&#125; &#x3D; this.props.form</span><br><span class="line">    const &#123;domArr,flag,info&#125;  &#x3D; this.state</span><br><span class="line">    console.log(domArr);</span><br><span class="line">    console.log(info);</span><br><span class="line">    return (</span><br><span class="line">        &lt;Form</span><br><span class="line">        name&#x3D;&quot;basic&quot;</span><br><span class="line">        onSubmit&#x3D;&#123;this.onFinish&#125;</span><br><span class="line">    &gt;</span><br><span class="line">           &lt;h5&gt;收费规则&lt;&#x2F;h5&gt;</span><br><span class="line">        &#123;flag? &lt;div&gt;&lt;Form.Item label&#x3D;&quot;合同编号&quot;  style&#x3D;&#123;&#123; display:&quot;flex&quot; &#125;&#125; &gt;</span><br><span class="line">            &#123;getFieldDecorator(&#39;concatNo&#39;, &#123;</span><br><span class="line">                rules: [&#123; required: true, message: &#39;该项是必填项&#39; &#125;],</span><br><span class="line">                initialValue: (info.length!&#x3D;&#x3D;0)?info[0].concatNo:&quot;&quot;</span><br><span class="line">            &#125;)(</span><br><span class="line">                &lt;Input style&#x3D;&#123;&#123; &#39;width&#39;: &#39;300px&#39; &#125;&#125; placeholder&#x3D;&quot;请输入合同编号&quot; &#x2F;&gt;,</span><br><span class="line">            )&#125;</span><br><span class="line">        &lt;&#x2F;Form.Item&gt;</span><br><span class="line"></span><br><span class="line">         &lt;Form.Item&gt;</span><br><span class="line">         &#123;getFieldDecorator(&#39;stubPeriodSetting&#39;, &#123;</span><br><span class="line">                rules: [&#123; required: true, message: &#39;该项是必填项&#39;,type: &#39;array&#39; &#125;],</span><br><span class="line">                initialValue:  &quot;&quot;</span><br><span class="line">            &#125;)(</span><br><span class="line">                &lt;TrusteeshipForm</span><br><span class="line">                    setFlag&#x3D;&#123;()&#x3D;&gt;&#123;this.setFlag&#125;&#125;</span><br><span class="line">                    domArr&#x3D;&#123;domArr&#125;</span><br><span class="line">                    onAdd &#x3D; &#123;this.onAdd&#125;</span><br><span class="line">                    onDel&#x3D;&#123;this.onDel&#125;</span><br><span class="line">                    onChange&#x3D;&#123;this.onChange&#125; &#x2F;&gt;,</span><br><span class="line">            )&#125;</span><br><span class="line">        &lt;&#x2F;Form.Item&gt;&lt;&#x2F;div&gt;:&quot;&quot;&#125;</span><br><span class="line">            &lt;Form.Item style&#x3D;&#123;&#123;display: &quot;flex&quot;,justifyContent:&quot;center&quot;&#125;&#125;&gt;</span><br><span class="line">            &lt;Button type&#x3D;&quot;dashed&quot; htmlType&#x3D;&quot;submit&quot;&gt;</span><br><span class="line">                保存</span><br><span class="line">            &lt;&#x2F;Button&gt;</span><br><span class="line">        &lt;&#x2F;Form.Item&gt;</span><br><span class="line">    &lt;&#x2F;Form&gt;</span><br><span class="line">    )</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">Trusteeship &#x3D; Form.create(&#123;&#125;)(Trusteeship)</span><br><span class="line"></span><br><span class="line">export default Trusteeship</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 引入react</span><br><span class="line">import React, &#123;</span><br><span class="line">    PureComponent</span><br><span class="line">&#125; from &#39;react&#39;;</span><br><span class="line">import &#123; Form, Button, Input, message,DatePicker &#125; from &quot;antd&quot;</span><br><span class="line">import fetchHandler from &#39;@&#x2F;fetch&#x2F;fetchHandler&#39;</span><br><span class="line">import &#123;companyList &#125; from &#39;@&#x2F;fetch&#x2F;fetchApi&#39;</span><br><span class="line">import AutoSearch from &#39;@&#x2F;components&#x2F;display&#x2F;input&#x2F;AutoSearch&#39;;</span><br><span class="line">import moment from &#39;moment&#39;;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">class TrusteeshipForm extends PureComponent &#123;</span><br><span class="line">    constructor(props) &#123;</span><br><span class="line">        super(props);</span><br><span class="line">        this.props &#x3D; props</span><br><span class="line">        this.state &#x3D; &#123;</span><br><span class="line">            domArr :this.props.domArr</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">   style &#x3D; &#123;</span><br><span class="line">    display: &#39;flex&#39;,</span><br><span class="line">    alignItems:&quot;center&quot;,</span><br><span class="line">    marginBottom:&quot;20px&quot;</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;    判断对象是否存在空值</span><br><span class="line">   getDetaios(arr) &#123;</span><br><span class="line">    for (var i in arr) &#123;</span><br><span class="line">      if (arr[i] &#x3D;&#x3D; null) &#123;</span><br><span class="line">        return true</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    return false</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">componentDidMount () &#123;</span><br><span class="line">    this.props.onChange(this.state.domArr)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">   onAdd &#x3D; ()&#x3D;&gt;&#123;</span><br><span class="line">       const &#123;domArr&#125; &#x3D; this.state</span><br><span class="line">       this.props.setFlag()</span><br><span class="line">       if(domArr.length&gt;&#x3D;10) &#123;</span><br><span class="line">        message.warning(&quot;最多添加10条！&quot;)</span><br><span class="line">        return</span><br><span class="line">       &#125;</span><br><span class="line">       if(this.getDetaios(domArr[domArr.length-1])) &#123;</span><br><span class="line">           message.warning(&quot;存在未填项或数据不正确，请检查！&quot;)</span><br><span class="line">           return</span><br><span class="line">       &#125;</span><br><span class="line">       let nextStartDate &#x3D; moment(new Date()).format(&quot;YYYY-MM-DD&quot;)</span><br><span class="line">       let nextEndDate &#x3D; moment(new Date()).add(7,&#39;day&#39;).format(&quot;YYYY-MM-DD&quot;)</span><br><span class="line">       if(domArr.length&gt;0) &#123;</span><br><span class="line">         nextStartDate &#x3D; moment(domArr[domArr.length-1].endDate).add(1,&#39;day&#39;).format(&quot;YYYY-MM-DD&quot;)</span><br><span class="line">         nextEndDate &#x3D; moment(nextStartDate).add(7,&#39;day&#39;).format(&quot;YYYY-MM-DD&quot;)</span><br><span class="line">       &#125;</span><br><span class="line"></span><br><span class="line">       const  obj &#x3D;&#123;</span><br><span class="line">        unitPrice:null,</span><br><span class="line">        paymentCompanyId:null,</span><br><span class="line">        startDate:nextStartDate,</span><br><span class="line">        endDate: nextEndDate,</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">       domArr.push(obj)</span><br><span class="line">           this.setState(&#123;</span><br><span class="line">               domArr,</span><br><span class="line">           &#125;,()&#x3D;&gt;&#123;</span><br><span class="line">               this.props.onAdd(domArr)</span><br><span class="line">           &#125;</span><br><span class="line">           )</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   startChange (startDate,index) &#123;</span><br><span class="line">    const domArr &#x3D; this.state.domArr</span><br><span class="line">    const time &#x3D; moment(startDate).diff(moment(domArr[index].endDate))</span><br><span class="line">    if(time&gt;0) &#123;</span><br><span class="line">        message.warning(&quot;开始时间必须在结束时间之前！&quot;)</span><br><span class="line">        return</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    domArr[index].startDate &#x3D; startDate</span><br><span class="line">       this.setState(&#123;</span><br><span class="line">        domArr</span><br><span class="line">       &#125;,()&#x3D;&gt;&#123;</span><br><span class="line">        const domArr &#x3D; this.state.domArr</span><br><span class="line">           this.props.onChange(domArr)</span><br><span class="line">           this.props.onAdd(domArr)</span><br><span class="line">       &#125;)</span><br><span class="line"></span><br><span class="line">   &#125;</span><br><span class="line">   endChange (endDate,index) &#123;</span><br><span class="line">    const domArr &#x3D; this.state.domArr</span><br><span class="line">    let time</span><br><span class="line">    if( domArr[index+1]) &#123;</span><br><span class="line">        time &#x3D; moment(endDate).diff(moment(domArr[index+1].endDate))</span><br><span class="line">    &#125;</span><br><span class="line">    if(time&gt;0||time&#x3D;&#x3D;&#x3D;0) &#123;</span><br><span class="line">       domArr.forEach((item,i)&#x3D;&gt;&#123;</span><br><span class="line">           if(i&gt;index) &#123;</span><br><span class="line">               item.endDate &#x3D; null</span><br><span class="line">               item.startDate &#x3D; null</span><br><span class="line">           &#125;</span><br><span class="line">       &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">    if(domArr[index+1]) &#123;</span><br><span class="line">        domArr[index+1].startDate &#x3D; moment(endDate).add(1,&#39;day&#39;).format(&quot;YYYY-MM-DD&quot;)</span><br><span class="line">    &#125;</span><br><span class="line">     domArr[index].endDate &#x3D; endDate</span><br><span class="line">       this.setState(&#123;</span><br><span class="line">        domArr</span><br><span class="line">       &#125;,()&#x3D;&gt;&#123;</span><br><span class="line">        const domArr &#x3D; this.state.domArr</span><br><span class="line">           this.props.onChange(domArr)</span><br><span class="line">           this.props.onAdd(domArr)</span><br><span class="line">       &#125;)</span><br><span class="line"></span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   feeChange (fee,index) &#123;</span><br><span class="line">    const domArr &#x3D; this.state.domArr</span><br><span class="line">    domArr[index].unitPrice &#x3D; fee</span><br><span class="line">       this.setState(&#123;</span><br><span class="line">        domArr</span><br><span class="line">       &#125;,()&#x3D;&gt;&#123;</span><br><span class="line">        const domArr &#x3D; this.state.domArr</span><br><span class="line">           this.props.onChange(domArr)</span><br><span class="line">           this.props.onAdd(domArr)</span><br><span class="line">       &#125;)</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line">   companyChange  (e,index) &#123;</span><br><span class="line">    const domArr &#x3D; this.state.domArr</span><br><span class="line">    domArr[index].paymentCompanyId &#x3D; e</span><br><span class="line">       this.setState(&#123;</span><br><span class="line">        domArr</span><br><span class="line">       &#125;,()&#x3D;&gt;&#123;</span><br><span class="line">        const domArr &#x3D; this.state.domArr</span><br><span class="line">           this.props.onChange(domArr)</span><br><span class="line">           this.props.onAdd(domArr)</span><br><span class="line">       &#125;)</span><br><span class="line">   &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    render() &#123;</span><br><span class="line">        const &#123;domArr&#125; &#x3D; this.state</span><br><span class="line">        return &lt;div style&#x3D;&#123;&#123;width:&quot;552px&quot;&#125;&#125;&gt;</span><br><span class="line">           &#123;domArr&amp;&amp;domArr.map((item,index)&#x3D;&gt;&#123;</span><br><span class="line">               return &lt;div key&#x3D;&#123;index&#125;&gt;</span><br><span class="line">               &lt;div style&#x3D;&#123;this.style&#125;&gt;</span><br><span class="line">                    &lt;label&gt;&lt;span style&#x3D;&#123;&#123;color:&quot;red&quot;&#125;&#125;&gt;*&lt;&#x2F;span&gt; 时间周期：&lt;&#x2F;label&gt;</span><br><span class="line">                     &lt;DatePicker</span><br><span class="line">                        placeholder&#x3D;&quot;开始时间&quot;</span><br><span class="line">                        disabled&#x3D;&#123;index!&#x3D;&#x3D;0&#125;</span><br><span class="line">                        value &#x3D; &#123;moment(item.startDate,&quot;YYYY-MM-DD&quot;)&#125;</span><br><span class="line">                        onChange&#x3D;&#123;(e,date)&#x3D;&gt;&#123;</span><br><span class="line">                        this.startChange(date,index)</span><br><span class="line">                    &#125;&#125;&#x2F;&gt;</span><br><span class="line">                     &lt;span&gt;—&lt;&#x2F;span&gt;</span><br><span class="line">                    &lt;DatePicker</span><br><span class="line">                    placeholder&#x3D;&quot;结束时间&quot;</span><br><span class="line">                    defaultValue&#x3D;&#123;moment(item.endDate,&quot;YYYY-MM-DD&quot;)&#125;</span><br><span class="line">                    disabledDate&#x3D;&#123;(current)&#x3D;&gt; &#123;</span><br><span class="line">                         return current &amp;&amp; current &lt;moment(item.startDate)</span><br><span class="line">                       &#125;&#125;</span><br><span class="line">                    onChange&#x3D;&#123;(e,date)&#x3D;&gt;&#123;</span><br><span class="line">                        this.endChange(date,index)</span><br><span class="line">                    &#125;&#125; &#x2F;&gt;</span><br><span class="line">               &lt;&#x2F;div&gt;</span><br><span class="line">               &lt;div style&#x3D;&#123;this.style&#125;&gt;</span><br><span class="line">                      &lt;label&gt;&lt;span style&#x3D;&#123;&#123;color:&quot;red&quot;&#125;&#125;&gt;*&lt;&#x2F;span&gt; 托管费用：&lt;&#x2F;label&gt;</span><br><span class="line">                      &lt;Input</span><br><span class="line">                       defaultValue&#x3D;&#123;item.unitPrice&#125;</span><br><span class="line">                       type&#x3D;&quot;number&quot;</span><br><span class="line">                       style&#x3D;&#123;&#123; &#39;width&#39;: &#39;300px&#39; &#125;&#125;</span><br><span class="line">                       onChange&#x3D;&#123;(e)&#x3D;&gt;&#123;</span><br><span class="line">                        this.feeChange(e.target.value,index)</span><br><span class="line">                       &#125;&#125;</span><br><span class="line">                       placeholder&#x3D;&quot;请输入托管费用&quot; addonAfter&#x3D;&quot;元&#x2F;年&quot; &#x2F;&gt;</span><br><span class="line">               &lt;&#x2F;div&gt;</span><br><span class="line">               &lt;div style&#x3D;&#123;this.style&#125;&gt;</span><br><span class="line">                  &lt;label&gt;&lt;span style&#x3D;&#123;&#123;color:&quot;red&quot;&#125;&#125;&gt;*&lt;&#x2F;span&gt; 承担企业：&lt;&#x2F;label&gt;</span><br><span class="line">               &lt;AutoSearch</span><br><span class="line">                  key&#x3D;&#123;item.companyName||&#39;add&#39;&#125;</span><br><span class="line">                  placeholder&#x3D;&#39;请输入商户名称模糊搜索&#39;</span><br><span class="line">                  config&#x3D;&#123;&#123;</span><br><span class="line">                    allowClear: true,&#x2F;&#x2F;是否允许清除,</span><br><span class="line">                    showParam: &#39;companyName&#39;, &#x2F;&#x2F; 展示的条目参数</span><br><span class="line">                    choseParam: &#39;companyId&#39;, &#x2F;&#x2F; 选中的参数</span><br><span class="line">                    sourceApi: companyList, &#x2F;&#x2F; 选项接口</span><br><span class="line">                    initialValue: item.companyName,</span><br><span class="line">                    fetchParams:&#123;</span><br><span class="line">                      status:1</span><br><span class="line">                    &#125;</span><br><span class="line">                  &#125;&#125;</span><br><span class="line">                  module&#x3D;&#39;company&#39;</span><br><span class="line">                  setValue&#x3D;&#123;(e) &#x3D;&gt; &#123;</span><br><span class="line">                    this.companyChange(e,index)</span><br><span class="line">                  &#125;&#125;</span><br><span class="line">                &#x2F;&gt;</span><br><span class="line">                 &lt;&#x2F;div&gt;</span><br><span class="line">                 &lt;hr&#x2F;&gt;</span><br><span class="line">               &lt;&#x2F;div&gt;</span><br><span class="line">               &#125;) &#125;</span><br><span class="line">                  &lt;div style&#x3D;&#123;&#123;display: &quot;flex&quot;,justifyContent:&quot;center&quot;&#125;&#125;&gt;</span><br><span class="line">                  &lt;Button  type&#x3D;&quot;primary&quot;  onClick&#x3D;&#123;()&#x3D;&gt;&#123;</span><br><span class="line">                       this.onAdd()</span><br><span class="line">                   &#125;&#125;&gt; 添加规则&lt;&#x2F;Button&gt;</span><br><span class="line">                   &#123;domArr&amp;&amp;domArr.length!&#x3D;&#x3D;0? &lt;Button style&#x3D;&#123;&#123;marginLeft:&quot;20px&quot;&#125;&#125; type&#x3D;&quot;primary&quot; onClick&#x3D;&#123;()&#x3D;&gt;&#123;</span><br><span class="line">                       this.props.onDel()</span><br><span class="line">                  &#125;&#125;&gt;删除&lt;&#x2F;Button&gt;:&quot;&quot;&#125;</span><br><span class="line">                 &lt;&#x2F;div&gt;</span><br><span class="line"></span><br><span class="line">              &lt;&#x2F;div&gt;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">TrusteeshipForm &#x3D; Form.create(&#123;&#125;)(TrusteeshipForm)</span><br><span class="line"></span><br><span class="line">export default TrusteeshipForm;</span><br><span class="line"></span><br></pre></td></tr></table></figure> 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://gitee.com/shimmer612/myBlog/2021/07/30/2021-07-30-%E8%A1%A8%E5%8D%95%E6%B7%BB%E5%8A%A0%E5%A4%9A%E7%BB%84%E8%A7%84%E5%88%99/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/myBlog/tags/antd/" rel="tag">antd</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/myBlog/2021/08/12/2021-08-12-%E6%96%87%E4%BB%B6%E4%BD%9C%E4%B8%BA%E5%8F%82%E6%95%B0%E4%B8%8A%E4%BC%A0/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            文件作为参数上传
          
        </div>
      </a>
    
    
      <a href="/myBlog/2021/06/30/2021-06-30-%E6%98%9F%E7%90%83%E7%A9%BA%E9%97%B4%E7%AB%99%E9%A1%B9%E7%9B%AE%E6%80%BB%E7%BB%93/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">星球空间站项目总结</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "xGZKFxfEhEyqsK7YA4NNoQNr-gzGzoHsz",
    app_key: "qCe4kOh0W9rCgNWcv31cO3NF",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "说出你想说的吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
   
     
</article>

</section>
      <!--
 * @Author: zhangzhen
 * @Date: 2023-02-04 10:30:09
 * @LastEditors: zhangzhen
 * @LastEditTime: 2023-05-23 09:47:12
 * 
-->
<footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2021-2023
        <i class="ri-heart-fill heart_icon"></i> Shimmer
      </li>
    </ul>
    <!-- <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul> -->
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/myBlog/"><img src="/myBlog/images/ayer-side.svg" alt="Shimmer"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/myBlog/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/myBlog/archives">目录</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/myBlog/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/myBlog/photos">相册</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/myBlog/2021/02/12/2021-02-12-%E5%85%B3%E4%BA%8E%E6%88%91/">关于我</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/myBlog/message">留言板</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/myBlog/js/jquery-2.0.3.min.js"></script>


<script src="/myBlog/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/myBlog/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/myBlog/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/myBlog/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->


<script src="/myBlog/js/clickBoom2.js"></script>


<!-- CodeCopy -->


<link rel="stylesheet" href="/myBlog/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>

</html>